package com.dianrui.firemenmonitor;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;
import android.support.multidex.MultiDex;

import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.dianrui.firemenmonitor.util.GlideImageLoader;
import com.dianrui.firemenmonitor.util.Static;

import cn.finalteam.galleryfinal.CoreConfig;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.ImageLoader;
import cn.finalteam.galleryfinal.ThemeConfig;

public class MyApplication extends Application {

    private static FunctionConfig functionConfig;
    private ImageLoader imageloader;
    private CoreConfig coreConfig;


    @Override
    public void onCreate() {
        super.onCreate();
        SDKInitializer.initialize(this);
        SDKInitializer.setCoordType(CoordType.BD09LL);
        Static.CONTEXT = this;
        initCameraConfig();
        repairAndroidOsFileUriExposedException();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }


    public void repairAndroidOsFileUriExposedException() {
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            builder.detectFileUriExposure();
        }
    }

    public void initCameraConfig() {
        if (functionConfig == null) {
            //配置功能
            functionConfig = new FunctionConfig.Builder().setMutiSelectMaxSize(9)
                    .setEnableEdit(true)
                    .setEnableCrop(true)
                    .setEnableRotate(false)
                    .setEnableCamera(false)
                    .setCropSquare(true)
                    .setRotateReplaceSource(false)
                    .setCropReplaceSource(false)
                    .setForceCrop(false)
                    .setForceCropEdit(true)
                    .setEnablePreview(true)
                    .build();
            //配置imageloader
            imageloader = new GlideImageLoader();
            //核心配置
            coreConfig = new CoreConfig.Builder(getApplicationContext(), imageloader, new ThemeConfig.Builder().setTitleBarBgColor(getResources().getColor(R.color.blue)).build()).setFunctionConfig(functionConfig).build();
            GalleryFinal.init(coreConfig);
        }

    }
    public static FunctionConfig getFunctionConfig() {
        return functionConfig;
    }
}
